-- SoundEngine
-- 音效管理？
SoundEngine = class()

function SoundEngine:init()
    self.musics = {}
    self.callBack = {}
    self.lastTick = 0
end

function SoundEngine:addMusic(fileName)
    table.insert(self.musics,fileName)
end

function SoundEngine:clearMusic()
    self.musics = {}
end

function SoundEngine:addCallBack(func)
    table.insert(self.callBack,func)
end

function SoundEngine:hasMusic()
    return #self.musics > 0
end

function SoundEngine:tick()
    if ElapsedTime - self.lastTick > 0.5 and #self.musics > 0 and music.currentTime == 0 then
        music(self.musics[1])
        table.remove(self.musics,1)
        for k,v in pairs(self.callBack) do
            v()
        end
        self.lastTick = ElapsedTime
    end
end
